/**
 * 重写request命令
 */
Cypress.Commands.overwrite('request', (originalFn, options) => {
    let url = options.url || '';

    if (url.indexOf('?') == -1) {
        url += '?';
    }

    if (url.indexOf('&') != -1) {
        url += '&';
    }

    url += `AppID=${Cypress.env('AppID')}&AppSecret=${Cypress.env('AppSecret')}`;

    options.url = url;

    if (!options.headers) {
        options.headers = {
            'content-type': 'application/x-www-form-urlencoded'
        };
    }

    return originalFn(options);
});

/**
 * 验证返回分页数据
 */
Cypress.Commands.add('validPagedData', (response, pageSize) => {
    expect(response.status, '调用成功').to.be.equal(200);
    expect(response.body, '正常返回数据').to.property('code', 0);
    expect(response.body.data, '正确返回分页总记录数').to.property('totalCount');
    expect(response.body.data, '正确返回分页数据').to.property('dataList');

    expect(response.body.data.dataList.length, '分页数据正确').to.lte(pageSize || 20);
});